<?php
session_start();
header('Content-Type: text/html; charset=UTF-8');
define('URI', 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], 'index.php')));
define('PAGES_PATH', '/pages/');


$_CATEGORY = (!empty($_GET['cat']) ) ? $_GET['cat'] : 'home';

// PART 
$path = __DIR__  . PAGES_PATH . $_CATEGORY . '.php';
ob_start();
if ( file_exists($path) ) { 
  include $path ;
}
$_CONTENTS = ob_get_contents();
ob_end_clean();

// LAYOUT
if ( isset($_POST['ajax']) AND $_POST['ajax'] === "true" ) {
  echo $_CONTENTS;
}
else {
  $path = __DIR__ . '/layout.php';
  ob_start();
  if ( file_exists($path) ) { 
    include $path ;
  }
  ob_end_flush();
}